<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2012-3-9 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'servlet/module/master.mod.php';

class moduleObj extends masterObj
{
	function __construct($request)
	{
		parent::__construct($request);
		
		//require_once ROOT_PATH.'include/logic/image.logic.php';
		
		$this->excute();
	}
	
	private function excute()
	{
		switch($this->act)
		{
			case 'list':
				$this->getList();
				break;
			case 'search';
				$this->searchSeafood();
				break;
			case 'business_recommend':
				$this->getRecommendBusiness();
				break;
			default:
				$this->message('g_04', STATUS_E);
				break;
		}
		
		$this->showResponse();
	}

	private function getList()
	{
		$result = get_seafood_list($this->request);
		
		if(!check_array($result['result'])) $this->message('s_01', STATUS_F);
		
		foreach($result['result'] as &$temp)
		{
			$temp['image'] = ($temp['image'] != '') ? BASE_URL.$temp['image'] : '';
			$temp['image_s'] = str_replace('_o.', '_s.', $temp['image']);
			
			$temp['image_s'] = date('Y-m-d', $temp['image_s']);
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($result['result']);
		$this->response['list'] = $result['result'];
	}
	
	private function searchSeafood()
	{
		$result = get_seafood_list($this->request);
		
		if(!check_array($result['result'])) $this->message('s_01', STATUS_F);
		
		foreach($result['result'] as &$temp)
		{
			$temp['image'] = ($temp['image'] != '') ? BASE_URL.$temp['image'] : '';
			$temp['image_s'] = str_replace('_o.', '_s.', $temp['image']);
			
			$temp['image_s'] = date('Y-m-d', $temp['image_s']);
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($result['result']);
		$this->response['list'] = $result['result'];
	}
	
	private function getRecommendBusiness()
	{
		$result = get_seafood_recommend_list($this->request);
		
		if(!check_array($result)) $this->message('s_02', STATUS_F);
		
		foreach($result as &$temp)
		{
			$temp['business_logo'] = ($temp['business_logo'] != '') ? BASE_URL.$temp['business_logo'] : '';
			$temp['business_logo_s'] = str_replace('_o.', '_s.', $temp['business_logo']);
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($result);
		$this->response['list'] = $result;
	}
}